using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using T2.WebSecurity.Data.Controllers.Interfaces;
using T2.WebSecurity.Data.Entities.Interfaces;
using T2.WebSecurity.Business.Entities.Interfaces;
using T2.WebSecurity.Business.Entities;
using T2.WebSecurity.Business.Builders;
using T2.WebSecurity.Business.Directors.Interface;
using T2.WebSecurity.Business.Entities.Search.Interfaces;

//--Change Management Control - UserProfile Director  --**********************
//--Created By: trooks
//--Description: UserProfile Director Class
//--Created Date: 03/07/2013 10:48:31
//--*************************************************************

namespace T2.WebSecurity.Business.Directors
{
	public partial class UserProfile_Director_biz : IUserProfile_director_biz
	{
		
		public List<IUserProfile_biz> Construct (IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			UserProfile_Builder build = new UserProfile_Builder();
			List<IUserProfile_biz> retVal = build.BuildParts(_param);
			foreach(IUserProfile_biz item in retVal)
			{
				item.Membership_List = BuildMembershipList(item, false, BuildDown);
				item.OAuthMembership_List = BuildOAuthMembershipList(item, false, BuildDown);
				item.UsersInRoles_List = BuildUsersInRolesList(item, false, BuildDown);
				item.UserProfileData_List = BuildUserProfileDataList(item, false, BuildDown);
				item.ApplicationUser_List = BuildApplicationUserList(item, false, BuildDown);
		}
			return retVal;
		}
		public List<IUserProfile_biz> Construct (IUserProfileSearch_biz _param, bool BuildUp, bool BuildDown)
		{
			UserProfile_Builder build = new UserProfile_Builder();
			List<IUserProfile_biz> retVal = build.BuildParts(_param);
			foreach(IUserProfile_biz item in retVal)
			{
				item.Membership_List = BuildMembershipList(item, false, BuildDown);
				item.OAuthMembership_List = BuildOAuthMembershipList(item, false, BuildDown);
				item.UsersInRoles_List = BuildUsersInRolesList(item, false, BuildDown);
				item.UserProfileData_List = BuildUserProfileDataList(item, false, BuildDown);
				item.ApplicationUser_List = BuildApplicationUserList(item, false, BuildDown);
		}
			return retVal;
		}
		private List<IMembership_biz> BuildMembershipList(IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IMembership_biz> retVal = new List<IMembership_biz>();
			if(BuildDown)
			{
			IMembership_biz MembershipParam = new Membership_biz();
			MembershipParam.Action ="UserProfile_Membership_ByParent";
			MembershipParam.PageNumber = 1;
			MembershipParam.PageSize = 100;
			MembershipParam.SortType = "asc";
			MembershipParam.SortColumn = "MembershipID";
			MembershipParam.UserId = _param.UserId;
			Membership_Builder builder = new Membership_Builder();
			retVal = builder.BuildParts(MembershipParam);
			}
			return retVal;
		}
		private List<IOAuthMembership_biz> BuildOAuthMembershipList(IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IOAuthMembership_biz> retVal = new List<IOAuthMembership_biz>();
			if(BuildDown)
			{
			IOAuthMembership_biz OAuthMembershipParam = new OAuthMembership_biz();
			OAuthMembershipParam.Action ="UserProfile_OAuthMembership_ByParent";
			OAuthMembershipParam.PageNumber = 1;
			OAuthMembershipParam.PageSize = 100;
			OAuthMembershipParam.SortType = "asc";
			OAuthMembershipParam.SortColumn = "OAuthMembershipID";
			OAuthMembershipParam.UserId = _param.UserId;
			OAuthMembership_Builder builder = new OAuthMembership_Builder();
			retVal = builder.BuildParts(OAuthMembershipParam);
			}
			return retVal;
		}
		private List<IUsersInRoles_biz> BuildUsersInRolesList(IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IUsersInRoles_biz> retVal = new List<IUsersInRoles_biz>();
			if(BuildDown)
			{
			IUsersInRoles_biz UsersInRolesParam = new UsersInRoles_biz();
			UsersInRolesParam.Action ="UserProfile_UsersInRoles_ByParent";
			UsersInRolesParam.PageNumber = 1;
			UsersInRolesParam.PageSize = 100;
			UsersInRolesParam.SortType = "asc";
			UsersInRolesParam.SortColumn = "UsersInRoleID";
			UsersInRolesParam.UserId = _param.UserId;
			UsersInRoles_Builder builder = new UsersInRoles_Builder();
			retVal = builder.BuildParts(UsersInRolesParam);
			}
			return retVal;
		}
		private List<IUserProfileData_biz> BuildUserProfileDataList(IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IUserProfileData_biz> retVal = new List<IUserProfileData_biz>();
			if(BuildDown)
			{
			IUserProfileData_biz UserProfileDataParam = new UserProfileData_biz();
			UserProfileDataParam.Action ="UserProfile_UserProfileData_ByParent";
			UserProfileDataParam.PageNumber = 1;
			UserProfileDataParam.PageSize = 100;
			UserProfileDataParam.SortType = "asc";
			UserProfileDataParam.SortColumn = "UserProfileDataID";
			UserProfileDataParam.UserId = _param.UserId;
			UserProfileData_Builder builder = new UserProfileData_Builder();
			retVal = builder.BuildParts(UserProfileDataParam);
			}
			return retVal;
		}
		private List<IApplicationUser_biz> BuildApplicationUserList(IUserProfile_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IApplicationUser_biz> retVal = new List<IApplicationUser_biz>();
			if(BuildDown)
			{
			IApplicationUser_biz ApplicationUserParam = new ApplicationUser_biz();
			ApplicationUserParam.Action ="UserProfile_ApplicationUser_ByParent";
			ApplicationUserParam.PageNumber = 1;
			ApplicationUserParam.PageSize = 100;
			ApplicationUserParam.SortType = "asc";
			ApplicationUserParam.SortColumn = "ApplicationUserID";
			ApplicationUserParam.UserId = _param.UserId;
			ApplicationUser_Builder builder = new ApplicationUser_Builder();
			retVal = builder.BuildParts(ApplicationUserParam);
			}
			return retVal;
		}
	}
}